home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / sound / speech recognition sample / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  2.8 KB  |  124 lines

  1. /*
  2.     File:        main.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/2/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #ifndef __MAIN__
  24. #include "main.h"
  25. #endif
  26.  
  27. //Globals
  28.     Boolean                gDone            = false;
  29.     SpeechChannel        theSpeechChan    = nil;
  30.  
  31. void main (void)
  32. {
  33.     SpeechInfoStruct    theSpeechInfo;
  34.     EventRecord            event;
  35.     OSErr                theErr            = noErr;
  36.     Boolean                gotEvent        = false;
  37.  
  38.     ToolBoxInit ();
  39.  
  40.     theErr = SpeakWelcome ();
  41.     if (theErr == noErr) {
  42.         theErr = ListenToUser (&theSpeechInfo);
  43.     }
  44.  
  45.     while (theErr == noErr && (gDone == false || SpeechBusy() != 0)) {    //Don't quit if we're talking to you
  46.         gotEvent = WaitNextEvent (everyEvent, &event, 6, nil);
  47.         if (gotEvent) {
  48.             switch (event.what)
  49.             {
  50.                 case keyDown:
  51.                     gDone = true;    //want to be able to quit if speech recognition isn't working
  52.                     break;
  53.                 case kHighLevelEvent :
  54.                     AEProcessAppleEvent (&event);    //Handle speech recognition events
  55.                     break;
  56.                 case mouseUp:
  57.                 case mouseDown:
  58.                 case keyUp:
  59.                 case autoKey:
  60.                 case updateEvt:
  61.                 case diskEvt:
  62.                 case activateEvt:
  63.                 case osEvt:
  64.                     break;
  65.             }
  66.         }
  67.     }
  68.  
  69.     theErr = SRCloseRecognitionSystem (theSpeechInfo.recogSystem);
  70. }
  71.  
  72. OSErr        SpeakWelcome        (void)
  73. {
  74.     OSErr                theErr            = noErr;
  75.  
  76.     theErr = GetNewSpeechChan (&theSpeechChan);        //Set up a global speech channel
  77.  
  78.     return theErr;
  79. }
  80.  
  81. OSErr        ListenToUser        (SpeechInfoPtr theSpeechInfo)
  82. {
  83.     OSErr                theErr            = noErr;
  84.  
  85.     theSpeechInfo->ID                = 'myID';
  86.     theSpeechInfo->recogSystem        = 0;
  87.     theSpeechInfo->theRecognizer    = 0;
  88.     theSpeechInfo->languages        = nil;
  89.     theSpeechInfo->SpeechDoneUPP    = nil;
  90.     theSpeechInfo->attributes        = 0;
  91.  
  92.     theErr = InitSpeechRecognition (theSpeechInfo);
  93.  
  94.     if (theErr == noErr) {
  95.         theErr = OpenSpeechRecognition (theSpeechInfo);
  96.     }
  97.  
  98.     if (theErr == noErr) {
  99.         theErr = ConfigureRecognition (theSpeechInfo);
  100.     }
  101.  
  102.     if (theErr == noErr) {
  103.         theErr = GetNewRecognizer (theSpeechInfo);
  104.     }
  105.  
  106.     if (theErr == noErr) {
  107.         theErr = SetSpeechDoneAEHander (theSpeechInfo);
  108.     }
  109.  
  110.     if (theErr == noErr) {
  111.         theErr = InstallRecogAEHandler (theSpeechInfo);
  112.     }
  113.  
  114.     if (theErr == noErr) {
  115.         theErr = MakeNewLanguage (theSpeechInfo);
  116.     }
  117.  
  118.     if (theErr == noErr) {
  119.         theErr = SRStartListening (theSpeechInfo->theRecognizer);
  120.     }
  121.  
  122.     return theErr;
  123. }
  124.